package org.shj.spark.core;

import java.util.Arrays;
import java.util.List;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.util.LongAccumulator;

public class AccumulatorValue {

	public static void main(String[] args) {
		SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("BroadCastValue");
		JavaSparkContext sc = new JavaSparkContext(conf);
		
		List<Integer> list = Arrays.asList(1,2,3,4,5);
		
		LongAccumulator longAccumulator = sc.sc().longAccumulator("sumAccumulator");
		sc.parallelize(list).foreach(x -> longAccumulator.add(x));
		
		System.out.println(longAccumulator.value());
		
		sc.close();

	}

}
